package com.ddy.unitTest;

import com.alibaba.fastjson.JSON;
import com.ddy.test.singleton.EnumSingleton;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;


/**
 * Created by ddy on 2020/4/20 1:21 PM
 */

public class EnumSingletonTest {

    /**
     * t1 running...
     * t1 : com.ddy.test.singleton.EnumSingleton@71dac704
     * t1 write log : com.ddy.test.singleton.EnumSingleton@71dac704
     * -------------
     * t2 running...
     * t2 : com.ddy.test.singleton.EnumSingleton@71dac704
     * t2 write log : com.ddy.test.singleton.EnumSingleton@71dac704
     * -------------
     */
    public static void main(String[] args){


        Thread thread1 = new Thread(new SingletonThread("t1"));
        Thread thread2 = new Thread(new SingletonThread("t2"));
        thread1.start();
        thread2.start();



    }

    static class SingletonThread implements Runnable{
        private String name;

        SingletonThread(String name){
            this.name = name;
        }

        @Override
        public void run() {
            System.out.println(name + " running...");
            EnumSingleton instance = EnumSingleton.getInstance();
            System.out.println(name + " : " + instance);
            try {
                sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            instance.log(name);
            System.out.println("-------------");
        }
    }
}
